package com.ikingtech.platform.service.tenant.service;

import com.ikingtech.framework.sdk.enums.system.tenant.TenantStatusEnum;
import com.ikingtech.framework.sdk.user.api.UserTenantApi;
import com.ikingtech.framework.sdk.user.model.UserTenantDTO;
import com.ikingtech.platform.service.tenant.entity.TenantDO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * @author tie yan
 */
@Service
@RequiredArgsConstructor
public class UserTenantService implements UserTenantApi {

    private final TenantService service;

    @Override
    public UserTenantDTO loadByCode(String code) {
        TenantDO entity = this.service.getByCode(code);
        UserTenantDTO userTenant = new UserTenantDTO();
        userTenant.setTenantId(entity.getId());
        userTenant.setTenantCode(entity.getCode());
        userTenant.setTenantName(entity.getName());
        userTenant.setTenantStatus(TenantStatusEnum.valueOf(entity.getStatus()));
        userTenant.setTenantStatusName(userTenant.getTenantStatus().description);
        userTenant.setTenantIcon(entity.getIcon());
        userTenant.setTenantLogo(entity.getLogo());
        return userTenant;
    }
}
